package com.suray.attendance.model.vo;

import io.swagger.annotations.ApiModel;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

/**
 * Description: 标准报工明细
 * Author: linyu
 * Date: 2023/11/2
 */
@ApiModel(value = "ProductionDataCollectDetailVo")
public class ProductionDataCollectDetailVo implements Serializable {

    private static final long serialVersionUID = 214213L;

    private String productionDate; // 生产日期
    private String employeeNo; // 人员编号
    private Long laborHours;  // 使用人时  3600=1h  erp的数据类型是Int32
    private BigDecimal qty; // 数量
    private String unitNo; // 单位编号
    private String pieceType; // 计件类型
    private String remark;
    private String technologyCode;
    private String projectReportErpCode;

    public String getProductionDate() {
        return productionDate;
    }

    public String getEmployeeNo() {
        return employeeNo;
    }

    public void setEmployeeNo(String employeeNo) {
        if(StringUtils.isEmpty(employeeNo)){
            throw new RuntimeException("employeeNo参数不能为空");
        }
        this.employeeNo = employeeNo;
    }

    public Long getLaborHours() {
        return laborHours;
    }

    public void setLaborHours(Long laborHours) {
        if(laborHours==null || laborHours.intValue()==0){
            throw new RuntimeException("laborHours参数不能为空");
        }
        this.laborHours = laborHours;
    }

    public BigDecimal getQty() {
        if(qty.equals(BigDecimal.ZERO)){
            return qty = new BigDecimal(1);
        }
        return qty;
    }

    public void setQty(BigDecimal qty) {
        this.qty = qty;
    }

    public String getUnitNo() {
        if(StringUtils.isEmpty(unitNo)){
            return "PCS"; // PCS           PCS1(有精度)
        }
        return unitNo;
    }

    public void setUnitNo(String unitNo) {
        this.unitNo = unitNo;
    }

    public String getPieceType() {
        if(StringUtils.isEmpty(pieceType)){
            return "1"; // 计件
        }
        return pieceType;
    }

    public void setPieceType(String pieceType) {
        this.pieceType = pieceType;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getTechnologyCode() {
        return technologyCode;
    }

    public void setTechnologyCode(String technologyCode) {
        if(StringUtils.isEmpty(technologyCode)){
            throw new RuntimeException("technologyCode参数不能为空");
        }
        this.technologyCode = technologyCode;
    }

    public String getProjectReportErpCode() {
        return projectReportErpCode;
    }

    public void setProjectReportErpCode(String projectReportErpCode) {
        if(StringUtils.isEmpty(projectReportErpCode)){
            throw new RuntimeException("projectReportErpCode参数不能为空");
        }
        this.projectReportErpCode = projectReportErpCode;
    }

    public void setProductionDate(String productionDate) {
        // Validate productionDate format
        try {
            DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
            LocalDate parsedDate = LocalDate.parse(productionDate, dateTimeFormatter);
            // If parsing is successful, set the productionDate
            this.productionDate = productionDate;
        } catch (Exception e) {
            // Handle parsing error
            throw new IllegalArgumentException("Invalid production date format. Please provide the date in the format yyyy-MM-dd HH:mm:ss");
        }
    }

}
